package com.jay.lang.ref.clazz;

import java.lang.ref.PhantomReference;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;

//跟其他引用用途不同，get一直是null
public class PhantomReferenceCls {
	// -Xmx2m -Xms2m
	public static void main(String[] args) {
		Reference<Bean>[] referent = new PhantomReference[100000];
		ReferenceQueue<Bean> queue = new ReferenceQueue<Bean>();
		for (int i = 0; i < referent.length; i++) {
			referent[i] = new PhantomReference<Bean>(new Bean("mybean:" + i,
					100), queue);// throw Exception
		}

		System.out.println(referent[100].get());

	}
}
